/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { PureComponent } from "react";
import { connect } from "dva";
import { Button, Modal } from "antd";
import PageHeaderLayout from "@/layouts/PageHeaderLayout";
import InfoCheck from "@/components/InfoCheck";
import styles from "./style.less";

const { confirm } = Modal;
@connect(({ mall }) => ({
  mall
}))
export default class Mall extends PureComponent {

  componentDidMount = () => {
    const { dispatch } = this.props;
    dispatch({
      type: "mall/getStatus",
      payload: {}
    });
  };

  showConfirm = () => {
    const { dispatch } = this.props;
    confirm({
      title: "温馨提示",
      content: "请维护完企业信息后再开通商城业务，确定要开通商城业务？",
      okText: "开通",
      cancelText: "再考虑下",
      centered: true,
      className: "shopButton",
      onOk() {
        dispatch({
          type: "mall/getStatus",
          payload: {
            type: "reg"
          }
        });
      },
      onCancel() {
        console.log("Cancel");
      }
    });
  };

  render() {
    const {
      mall: { stateType, refused, hrefUrl }
    } = this.props;
    const urlHref = hrefUrl || null;
    return (
      <PageHeaderLayout title="快宝商城">
        <div className={styles.main}>
          <h2>快宝商城</h2>
          <p>帮你轻松玩转本地电商</p>
          <p>一店多商家入驻模式，快速搭建网上商城</p>
          <p>从商品销售、订单管理、售后服务、客户服务等，提供全套商城服务</p>
          <p>结合同城配送服务，实现快速高效的配送体系</p>
          <p>提供安全可靠的技术支持</p>
          <div style={{ margin: "50px 0 20px" }}>
            {stateType == "已审核" ? (
              <a className={styles.into} href={urlHref} target="_blank" rel="noopener noreferrer">
                进入商城
              </a>
            ) : (
              <div>
                {stateType == "待审核" ? (
                  <Button type="primary" size="large" disabled>
                    审核资料中
                  </Button>
                ) : (
                  <Button type="primary" size="large" onClick={this.showConfirm} disabled={false}>
                    免费开通
                  </Button>
                )}
              </div>
            )}
          </div>
          <div className={styles.why}>
            {refused && refused != "审核拒绝" ? (
              <span>
                开通商城业务失败，原因：
                <span>{refused}</span>
              </span>
            ) : (
              ""
            )}
          </div>
        </div>
        <InfoCheck />
      </PageHeaderLayout>
    );
  }
}
